home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
c
/
AMesaRTL.lha
/
Mesa-2.6
/
amiga
/
drivers
/
AmigaMesaRTL
/
amigamesartl.c
next >
Wrap
C/C++ Source or Header
|
1998-09-19
|
50KB
|
2,008 lines
/*
* Mesa 3-D graphics library
* Version: 2.3
* Copyright (C) 1995-1997 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* amigamesartl.c
*
* Version 1.0 27 Jun 1998
* by Jarno van der Linden
* jarno@kcbbs.gen.nz
*
* Based on ddsample.c ver 1.5
*
* Version 1.1 02 Aug 1998
* by Jarno van der Linden
* jarno@kcbbs.gen.nz
*
* - Fixed several bugs in glClear()
* - QUICKLOOP macros added
* - Noticed that { *x = p; x++; } is faster than { *x++ = p; }
* - Quantizer changed to plugin library
* - Use environment variables to select quantizer
*
* Version 2.0 19 Sep 1998
* by Jarno van der Linden
* jarno@kcbbs.gen.nz
*
* - (Get|Set)IndexRGB added
* - Set and get attributes added
* - Lots more tags handled
* - Added palette table for index mode
* - Demands at least v2 quantizers
* - Removed colourbase correction from index functions
* - Deprecated some tags replaced by QNTZR_#?
* - Changed CreateContext interface
* - Added Szymon Ulatowski's resizing changes
* - Changed "Quantizer" to "OutputHandler"
* - Automagic mesamain.library opening added
* - AMRTL_SupportsOH tag added
* - RGBA and ARGB byte order supported
* - RGBA byte order determined by OH_RGBAOrder
*
*/
/*
* This is a sample template for writing new Mesa device drivers.
* You'll have to rewrite all the pseudo code below.
*
* Let's say you're interfacing Mesa to a window/operating system
* called FOO. Replace all occurances of FOOMesa with the real name
* you select for your interface (i.e. XMesa, WMesa, AmigaMesa).
*
* You'll have to design an API for clients to use, defined in a
* header called Mesa/include/GL/FooMesa.h Use the sample as an
* example. The API should at least have functions for creating
* rendering contexts, binding rendering contexts to windows/frame
* buffers, etc.
*
* Next, you'll have to write implementations for the device driver
* functions described in dd.h
*
* Note that you'll usually have to flip Y coordinates since Mesa's
* window coordinates start at the bottom and increase upward. Most
* window system's Y-axis increases downward
*
* Functions marked OPTIONAL may be completely omitted by your driver.
*
* Your Makefile should compile this module along with the rest of
* the core Mesa library.
*/
#include <stdlib.h>
#include "GL/mesadriver.h"
#include "context.h"
#include "depth.h"
#include "macros.h"
#include "matrix.h"
#include "types.h"
#include "vb.h"
#include "gl/gl.h"
#include "gl/outputhandler.h"
#include "gl/mesamain.h"
#include <constructor.h>
#include <intuition/intuition.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/utility.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <m68881.h>
#include <dos.h>
#define RGBA(r,g,b,a) (((r)<<24) | ((g)<<16) | ((b)<<8) | (a))
#define ARGB(r,g,b,a) (((a)<<24) | ((r)<<16) | ((g)<<8) | (b))
#define WINWIDTH(w) ((w)->Width - (w)->BorderLeft - (w)->BorderRight)
#define WINHEIGHT(w) ((w)->Height - (w)->BorderTop - (w)->BorderBottom)
#define QUICKLOOP16(n,l) { register int ql_var; \
for(ql_var=0; ql_var<((n) & 15); ql_var++) \
{ l; }\
for(; ql_var<(n); ql_var+=16) \
{ l; l; l; l; l; l; l; l; l; l; l; l; l; l; l; l; } \
}
#define QUICKLOOP8(n,l) { register int ql_var; \
for(ql_var=0; ql_var<((n) & 7); ql_var++) \
{ l; }\
for(; ql_var<(n); ql_var+=8) \
{ l; l; l; l; l; l; l; l; } \
}
#define QUICKLOOP4(n,l) { register int ql_var; \
for(ql_var=0; ql_var<((n) & 3); ql_var++) \
{ l; }\
for(; ql_var<(n); ql_var+=4) \
{ l; l; l; l; } \
}
#define QUICKLOOP2(n,l) { register int ql_var; \
for(ql_var=0; ql_var<((n) & 1); ql_var++) \
{ l; }\
for(; ql_var<(n); ql_var+=2) \
{ l; l; } \
}
#define QUICKLOOP1(n,l) { register int ql_var; \
for(ql_var=0; ql_var<(n); ql_var++) \
{ l; } \
}
/*
* This struct contains all device-driver state information. Think of it
* as an extension of the core GLcontext from types.h.
*/
struct amiga_mesa_rtl_context {
GLcontext *gl_ctx; /* the core library context */
GLvisual *gl_visual;
GLframebuffer *gl_buffer; /* The depth, stencil, accum, etc buffers */
ULONG mode; /* RGB, Index, etc. */
ULONG rgbaorder; /* ORDER_RGBA, ORDER_ARGB */
unsigned long *buffer; /* The image buffer */
GLint width, height; /* Size of image buffer */
GLint wwidth, wheight; /* Current output size */
GLint reqwidth, reqheight; /* Requester buffer width and height */
BOOL justcreated; /* Context has just been created, not yet made current */
unsigned long pixel; /* current color index or RGBA pixel value */
unsigned long clearpixel; /* pixel for clearing the color buffers */
struct Library *outputhandler; /* Output handler library */
struct Library *mesamain; /* MesaMain library */
BOOL myoutputhandler; /* I opened the output handler */
ULONG indexpal[256][3]; /* Palette table for index mode */
ULONG a4; /* Global data pointer */
/* etc... */
};
/*
* REMEMBER: These functions may be called in
* mesamain's context, NOT mesadriver,
* so no automatic access to global data
*/
static const char *renderer_string(void)
{
/* No access to global data at A4, put the read-only
* string in the far section so that we have an
* absolute reference instead of A4 relative
*/
__far static const char renderer[] = "AmigaMesaRTL";
return renderer;
}
static void clear_index( GLcontext *ctx, GLuint index )
{
struct amiga_mesa_rtl_context *amesartl = (struct amiga_mesa_rtl_context *) ctx->DriverCtx;
/* implement glClearIndex */
/* usually just save the color index value in the amesartl struct */
amesartl->clearpixel = index;
}
static void clear_color_rgba( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
{
struct amiga_mesa_rtl_context *amesartl = (struct amiga_mesa_rtl_context *) ctx->DriverCtx;
/* implement glClearColor */
/* color components are floats in [0,1] */
/* usually just save the value in the amesartl struct */
amesartl->clearpixel = RGBA(r,g,b,a);
}
static void clear_color_argb( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
{
struct amiga_mesa_rtl_context *amesartl = (struct amiga_mesa_rtl_context *) ctx->DriverCtx;
/* implement glClearColor */
/* color components are floats in [0,1] */
/* usually just save the value in the amesartl struct */
amesartl->clearpixel = ARGB(r,g,b,a);
}
static void clear( GLcontext *ctx,
GLboolean all, GLint x, GLint y, GLint width, GLint height )
{
struct amiga_mesa_rtl_context *amesartl = (struct amiga_mesa_rtl_context *) ctx->DriverCtx;
unsigned long *bp;
unsigned char *bbp;
unsigned long p;
/*
* Clear the specified region of the current color buffer using the clear
* color or index as specified by one of the two functions above.
* If all==GL_TRUE, clear whole buffer, else just clear region defined
* by x,y,width,height
*/
p = amesartl->clearpixel;
y = amesartl->wheight-1-y;
if(amesartl->mode == AMRTL_RGBAMode)
{
if(all)
{
bp = amesartl->buffer;
QUICKLOOP16(amesartl->width*amesartl->height,
{
*bp = p;
bp++;
}
)
}
else
{
bp = amesartl->buffer+y*amesartl->width+x;
QUICKLOOP16(height,
{
QUICKLOOP16(width,
{
*bp = p;
bp++;
}
)
bp -= amesartl->width + width;
}
)
}
}
else
{
if(al